/*
 * 太原学院计算机系技术系（c)版权所有
 */
package cn.edu.tyu.finance.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.cj.x.protobuf.MysqlxConnection.Close;

/**
 *MYSQL数据库实用类
 * @author mengjingyi
 *@version 1.0
 */
@SuppressWarnings("unused")
public class DbUtil {
	/**
	 * 获取数据库连接
	 * @return 数据连接对象
	 */
	/**
	 * 关闭数据库连接、预编译对象和结果集
	 * @param conn 数据库连接
	 * @param ps 预编译对象
	 * @param rs 结果集
	 */
	 public static void backconn(Connection conn,PreparedStatement ps,ResultSet rs) {
	    	if(rs!=null) {
	    		try {
					rs.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    	}
	    	if(ps!=null) {
	    		try {
					ps.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    	}
	    	if(conn!=null) {
	    		try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    	}
	    }
	public static void main(String[] args) {
		DbUtil dbUtil=new DbUtil();
		@SuppressWarnings("static-access")
		Connection conn=dbUtil.getConnection();
        System.out.println(conn); 		
	}
  public static Connection getConnection() {
	  
	  Connection conn=null;
	  String url="jdbc:mysql://localhost:3306/financedb?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
	  try {
		Class.forName("com.mysql.cj.jdbc.Driver");
	} catch (ClassNotFoundException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	  
	  try {
		conn=DriverManager.getConnection(url,"root","root");
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  return conn;
  }
}  
